﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using GtsServer.Common;

namespace GtsServer.DAL
{
    public class PrizeConvertUserRecordDAL
    {
        public PrizeConvertUserRecordDAL()
        { }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(int pageIndex, int pageSize, string strWhere = "")
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from( select pcur.ID,pcur.PrizeID,pcur.CreateTime,case pcur.Stutas when '1' then '兑换' when '2' then '使用' end StutasName,pcur.PrizeCount,u.IMSI,u.IMEI,u.Mac,u.UserAccount,p.Name as PrizeName,ROW_NUMBER() OVER(order by pcur.CreateTime desc) as RowNumber ");
            strSql.Append(" FROM PrizeConvertUserRecord pcur left join [user] u on pcur.UserID=u.ID left join Prize p on pcur.PrizeID=p.ID  ");
            if (!string.IsNullOrEmpty(strWhere))
                strSql.Append(strWhere);
            strSql.Append(") a where  RowNumber BETWEEN " + ((pageIndex - 1) * pageSize + 1) + " and " + pageIndex * pageSize + ";");
            strSql.Append(" select COUNT(1) from PrizeConvertUserRecord pcur left join [user] u on pcur.UserID=u.ID left join Prize p on pcur.PrizeID=p.ID");
            if (!string.IsNullOrEmpty(strWhere))
                strSql.Append(strWhere);
            return DbHelperSQL.Query(strSql.ToString());
        }
    }
}
